﻿<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
    <link type="text/css" rel="stylesheet" href="/static/admin/plugin/bootstrap-fileinput/css/fileinput.css"/>
</head>
<body>
<div class="page-container">

    <div class=" float-e-margins">
        <div class="ibox-content">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">Task列表</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">Task添加</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class=" tab-pane active" id="tab-1">
                        <form action="" class="form-inline" id="" data-url="">
                            <div class="form-group">
                                <label class="control-label">
                                    <label class="control-label">开始时间：
                                        <input type="text" class="form-control date-search start_time" placeholder="">
                                    </label>
                                </label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    <label class="control-label">结束时间：
                                        <input type="text" class="form-control date-search end_time" placeholder="">
                                    </label>
                                </label>
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="key">请选择:</label>
                                <select id="key" class="form-control" name="key">
                                    <option value="id">ID</option>
                                    <option value="m_name">任务名</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="value">输入:</label>
                                <input class="form-control" id="value" type="text" name="value">
                            </div>
                            <button type="button" class="btn btn-primary" id="eventQuery">查询</button>
                            <button type="button" onclick="location.replace(location.href);" class="btn btn-success ">刷新</button>
                        </form>
                        <table id="tb_departments"></table>
                    </div>
                    <div class=" tab-pane" id="tab-2">
                        <div class="ibox-content">
                            <form class="form-horizontal" id="form" data-url="/TaskAdd">
                                <div class="hr-line-dashed"></div>
                                <div class="form-group has-success">
                                    <label class="col-sm-2 control-label">*任务名称</label>
                                    <div class="col-sm-10">
                                        <input id="m_name" type="text" name="m_name" value=""  class="form-control">
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="gift_id">
                                        <span class="c-red">*</span>奖励奖品：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <select class="form-control" name="gift_id" id="gift_id">
                                            <option value="" selected="">--请选择--</option>
                                            {volist name="data" id="vo" }
                                            <option value="{$vo['id']}">{$vo['gift_name']}</option>
                                            {/volist}

                                        </select>
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group has-success">
                                    <label class="col-sm-2 control-label">*礼物个数</label>
                                    <div class="col-sm-10">
                                        <input id="num" type="number" name="num" value="0"  class="form-control">
                                    </div>
                                </div>

                                <div class="hr-line-dashed"></div>
                                <div class="form-group has-success">
                                    <label class="col-sm-2 control-label" for="expire_time">
                                        <span class="c-red">*</span>有效时间：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <input type="text" class="date-search form-control" id="expire_time" name="expire_time">
                                    </div>
                                </div>

                                <div class="hr-line-dashed"></div>
                                <div class="form-group has-success">
                                    <label class="col-sm-2 control-label">*每日任务等级</label>
                                    <div class="col-sm-10">
                                        <input id="level" type="number" name="level" value="1"  class="form-control">
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group has-success">
                                    <label class="col-sm-2 control-label">*进阶任务</label>
                                    <div class="col-sm-10">
                                        <input id="advance_level" type="number" name="advance_level" value="0"  class="form-control">
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group has-success">
                                    <label class="col-sm-2 control-label">*每个任务的经验值</label>
                                    <div class="col-sm-10">
                                        <input id="empirical_value" type="number" name="empirical_value" value="0"  class="form-control">
                                    </div>
                                </div>

                                <div class="hr-line-dashed"></div>
                                <div class="form-group has-success">
                                    <label class="col-sm-2 control-label">*任务
                                    </label>
                                    <div class="col-sm-10">
                                        <div class="radio i-checks">

                                            <label><input type="radio"  name="m_type" value="1" checked> <i></i> 每日任务</label>
                                            <label><input type="radio" name="m_type"  value="2" checked> <i></i> 进阶任务</label>

                                        </div>

                                    </div>
                                </div>


                                <input id="img_address" name="down_url" type="hidden">
                                <div class="form-group">
                                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                                        <button class="btn btn-primary" type="button" onclick="commonSubmit(this)">添加
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script type="text/javascript" src="/static/admin/plugin/bootstrap-fileinput/js/fileinput.js"></script>

<script type="text/javascript" src="/static/admin/plugin/bootstrap-fileinput/js/locales/zh.js"></script>
<script>
    $(document).on('ready', function(){
        displayAll($("#img_url"));
        displayAll($("#android_url"));
        displayAll($("#ios_url"));
    });
    function displayAll(obj) {
        obj.fileinput({
            language: 'zh', //设置语言

            // uploadUrl: "/", //上传的地址

            allowedFileExtensions: ['apk', 'jpg', 'png','webp'],//接收的文件后缀

            uploadAsync: false, //默认异步上传

            // showUpload: true, //是否显示上传按钮

            showRemove: true, //显示移除按钮

            showPreview: true, //是否显示预览

            browseClass: "btn btn-primary", //按钮样式

            maxFileCount: 1, //表示允许同时上传的最大文件个数

            enctype: 'multipart/form-data',

            validateInitialCount: true,

            previewFileIcon: "<iclass =" + 'glyphicon glyphicon-king' + "></i>",

            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
        }).on("filebatchuploadsuccess", function (event, data) {
            if (data) {
                $("#img_address").val(data.response);
                console.log(data.response);
            }
        });
    }

    $(document).ready(function () {
        initTable();
    });

    function initTable() {
        $('#tb_departments').bootstrapTable({
            url: '/TaskIndexData',         //请求后台的URL（*）
            dataField: "data",
            method: 'get',                      //请求方式（*）
            striped: true,                      //是否显示行间隔色
            cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            queryParams: queryParams,//传递参数（*）
            showToggle: true,
            showRefresh: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            showColumns: true,                  //是否显示所有的列
            showPaginationSwitch: true,
            minimumCountColumns: 2,             //最少允许的列数

            columns: [{
                field: 'id',
                title: 'ID'
            }, {
                field: 'm_name',
                title: '任务名称'
            }, {
                field: 'gift_id',
                title: '礼物id'
            },{
                field: 'gift_name',
                title: '礼物名称'
            }, {
                field: 'num',
                title: '礼物个数'
            }, {
                field: 'expire_time',
                title: '有效时间',
                formatter: function (value, row, index) {
                   return format(row.expire_time);
               }
            }, {
                field: 'm_type',
                title: '任务',
                formatter:function(value, row, index){
                    if(row.m_type == 1){
                        return '每日任务';
                    }else{
                        return '进阶任务';
                    }
                }
            }, {
                field: 'level',
                title: '每日任务等级'
            }, {
                field: 'advance_level',
                title: '进阶任务'
            }, {
                field: 'empirical_value',
                title: '每个任务的经验值'
            },{
                field: 'Button',
                title: '操作',
                events: operateEvents,
                formatter: operateFormatter
            }]
        });
    }


    //得到查询的参数
    function queryParams(params) {
        params.offset = params.offset / params.limit + 1;
        params.start_time = $('.start_time').val();
        params.end_time = $('.end_time').val();
        params.key = $('#key').val();
        params.value = $('#value').val();
        return params;
    }


    function operateFormatter(value, row, index) {
        return [
            '<button type="button"  class="TableEdit btn btn-primary  btn-sm" style="margin-right:15px;">修改</button>'
        ].join('');
    }

    window.operateEvents = {
        //修改规则
        'click .TableEdit': function (e, value, row, index) {
            layer.open({
                type: 2,
                title: ['修改banner', 'font-size:18px;font-family:宋体;font-weight:700;'],
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['800px', '600px'],
                content: "/TaskEdit?id=" + row.id,
                offset: 'auto',
                scrollbar: false,
                end: function () {
                    $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
                }
            });
        }
    }
    //时间搜索插件
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        lay('.date-search').each(function () {
            laydate.render({
                elem: this,
                type: 'datetime',
                trigger: 'click',
                format: 'yyyy-MM-dd HH:mm:ss'
            });
        });
    });


    function commonSubmit(obj) {

        var m_name = $('#m_name').val();
        var gift_id = $('#gift_id').val();
        var num = $('#num').val();
        var expire_time = $('#expire_time').val();
        var level = $('#level').val();
        var advance_level = $('#advance_level').val();
        var empirical_value = $('#empirical_value').val();
        var m_type = $('#m_type').val();
        if(m_name ==='' || expire_time==='' || m_type===''){
            layer.msg('请填写完整', { icon: 2, time: 2000});
            return false;
        }

        var form = $("#form");
        var formData = new FormData(form[0]);
        $(obj).attr('disabled', true).addClass('disabled');
        var url_ = form.attr('data-url');
        $.ajax({
            url: url_,
            type: 'POST',
            dataType: 'json',
            // data: form.serialize(),
            data:formData,
            processData: false,
            contentType: false,
            cache: false,
            async: false,
            success: function (re) {
                // console.log(re);
                $(obj).removeAttr('disabled', true).removeClass('disabled');
                if (re.code === 1) {
                    layer.msg(re.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        re.url ? window.location.href = re.url : '';
                    });
                } else {
                    layer.alert(re.msg);
                }
            }
        });
        return false;
    }

    // 搜索按钮触发事件
    $(function () {
        $("#eventQuery").click(function () {
            $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
        });

    });
</script>
</body>
</html>